<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "shbb_product".
 *
 * @property integer $id
 * @property string $code
 * @property string $name
 * @property string $img
 * @property string $introduction
 * @property integer $rating_num
 * @property double $rating_score
 * @property integer $park_id
 *
 * @property ShbbPark $park
 * @property ShbbProductAuth[] $shbbProductAuths
 * @property ShbbProductSale[] $shbbProductSales
 */
class Product extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'shbb_product';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['introduction'], 'string'],
            [['rating_num', 'park_id'], 'integer'],
            [['rating_score'], 'number'],
            [['code', 'name', 'img'], 'string', 'max' => 255]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'code' => 'Code',
            'name' => 'Name',
            'img' => 'Img',
            'introduction' => 'Introduction',
            'rating_num' => 'Rating Num',
            'rating_score' => 'Rating Score',
            'park_id' => 'Park ID',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getPark()
    {
        return $this->hasOne(ShbbPark::className(), ['id' => 'park_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbProductAuths()
    {
        return $this->hasMany(ShbbProductAuth::className(), ['product_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShbbProductSales()
    {
        return $this->hasMany(ShbbProductSale::className(), ['product_id' => 'id']);
    }
}
